<template>
  <div>
    <h1 align="center">房号录入</h1>
    <table class="table table-bordered">
      <tr>
        <td align="center">门店</td>
        <td>
          <select v-model="state.mid">
            <option value="">全部</option>
            <option  :value="item.mid" v-for="item in list">{{item.m_name}}</option>
          </select>
        </td>
      </tr>
      <tr>
        <td align="center">房间号</td>
        <td>
          <input type="text" v-model="state.f_hao" />
        </td>
      </tr>
      <tr>
        <td align="center">备注</td>
        <td>
          <textarea cols="30" rows="3" v-model="state.f_dexc"></textarea>
        </td>
      </tr>
      <tr>
        <td align="center">房型</td>
        <td>
          <select v-model="state.xid">
            <option value="">全部</option>
            <option  :value="item.xid" v-for="item in listkku">{{item.x_name}}</option>
          </select>
        </td>
      </tr>
      <tr>
        <td align="center" colspan="2">
          <input type="button" value="新增" @click="ok" />
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
let data: any = reactive({
  state: {
    f_hao: '',
    f_dexc: '',
    mid: 0,
    xid: 0,
  },
  list:[],
  listkku:[]
});
let { state,list,listkku } = toRefs(data);

onMounted(()=>{
   getmdian();
   getfangxing();
})
//获取门店
const getmdian=()=>{
    axios({
      url:'/api/Member/m_Memdianmesses',
      method:'get'
    })
    .then(res=>{
      console.log(res);
      list.value=res.data.data
    })
    .catch(err=>{
      console.log(err)
    })
}
//获取房型
const getfangxing=()=>{
    axios({
      url:'/api/Member/x_Fangxings',
      method:'get'
    })
    .then(res=>{
      console.log(res);
      listkku.value=res.data.data
    })
    .catch(err=>{
      console.log(err)
    })
}

//房号录入
const ok = () => {
  let obj = {
    f_hao: state.value.f_hao,
    f_dexc: state.value.f_dexc,
    mid: state.value.mid,
    xid: state.value.xid,
  };
  axios({
    url: '/api/Member/fadd',
    method: 'post',
    data: obj
  })
    .then((res) => {
      console.log(res);
      if (res.data.data == 1) {
        alert('录入成功');
        router.push('/mshow');
      } else if (res.data.data == -1) {
        alert('房号名称重复');
        return;
      } else {
        alert('录入失败');
        return;
      }
    })
    .catch((err) => {
      console.log(err);
    });
};
</script>

<style scoped></style>
